% !TEX encoding = UTF-8 Unicode
% !TEX TS-program = XeLaTeX
% !TEX root = ParliamentUserGuide.tex

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\chapter{Building Berkeley DB for Windows}
\label{chapter-building-bdb-for-windows}

The build infrastructure for Berkeley DB is not particularly friendly for Windows.  Therefore, the \ac{pmnt} dependencies archive includes pre-built Berkeley DB libraries (both 32- and 64-bit).

This appendix is provided primarily to guide the developer who needs to update the pre-built libraries, e.g., for a new version of Berkeley DB or to build with a different compiler.  If this does not apply to you, then you may skip this appendix.

\begin{enumerate}
\item\label{step-download}Download the source code distribution for Berkeley DB and unzip it to a directory of your choice on your local disk.  Unless otherwise specified, all paths mentioned below are relative to this location.

\item In Visual Studio 2017, open this solution file:
	\begin{verbatim}
   build_windows\Berkeley_DB_vs2010.sln
	\end{verbatim}

\item If Visual Studio asks to update the projects' file format, allow it.  If not, right-click the solution in the Solution Explorer and choose Retarget Solution to cause the update to occur.

\item For each configuration-platform pair listed in Table~\ref{vs-config-platform-pairs}, choose Configuration Manager from the Build menu and select that configuration and platform.  Then, in the Solution Explorer, right-click the ``db'' project and choose ``Project Only / Build Only db'' from the menu.

	\begin{table}[htbp]
		\centering
		\begin{tabular}{cc}
			\toprule
			\textbf{Configuration} & \textbf{Platform} \\
			\midrule
			Debug   & Win32 \\
			Release & Win32 \\
			Debug   & x64   \\
			Release & x64   \\
			\bottomrule
		\end{tabular}
		\caption{Visual Studio Configuration-Platform Pairs}
		\label{vs-config-platform-pairs}
	\end{table}

\item Close Visual Studio.

\item\label{step-creates-dirs}Create the directory hierarchy shown in Figure~\ref{fig:bdbDirTree} at the root level of your dependencies directory.  (You will likely need to move or rename the \path|bdb| directory that is already present in that location.)
\begin{figure}[htbp]
	\centering
	\begin{minipage}[t]{3in}
		\dirtree{.1 dependencies.
			.2 bdb.
			.3 include.
			.3 msvc-14.1.
			.4 32.
			.4 64.
		}
	\end{minipage}
	\caption{BDB Directory Hierarchy}
	\label{fig:bdbDirTree}
\end{figure}

\item Copy these files into the \path|msvc-14.1\32| directory created in Step~\ref{step-creates-dirs} above:
\begin{verbatim}
   build_windows\Win32\Debug\libdb53d.dll
   build_windows\Win32\Debug\libdb53d.lib
   build_windows\Win32\Debug\libdb53d.pdb
   build_windows\Win32\Release\libdb53.dll
   build_windows\Win32\Release\libdb53.lib
   build_windows\Win32\Release\libdb53.pdb
\end{verbatim}

\item Copy these files into the \path|msvc-14.1\64| directory created in Step~\ref{step-creates-dirs} above:
\begin{verbatim}
   build_windows\x64\Debug\libdb53d.dll
   build_windows\x64\Debug\libdb53d.lib
   build_windows\x64\Debug\libdb53d.pdb
   build_windows\x64\Release\libdb53.dll
   build_windows\x64\Release\libdb53.lib
   build_windows\x64\Release\libdb53.pdb
\end{verbatim}

\item Copy these files into the \path|include| directory created in Step~\ref{step-creates-dirs} above:
\begin{verbatim}
   build_windows\*.h
\end{verbatim}

\item\label{step-zip-dependencies}Zip the dependencies directory into a file named
\begin{verbatim}
   parliament-dependencies-YYYY-MM-DD.zip
\end{verbatim}
with the current date in the obvious location.

\item Tag the repository with a command like the following:
\begin{verbatim}
   git tag -a -m "Tag made on YYYY-MM-DD just prior to
   version X.Y.Z.  Denotes time dependencies zip was
   released." dependencies-YYYY-MM-DD
\end{verbatim}

\item On GitHub, create a new release for the tag with the zip file from Step~\ref{step-zip-dependencies} as an attached binary.

\item Finally, delete the build directory that you created in Step~\ref{step-download} by unzipping the source code distribution.
\end{enumerate}
